#include <stdio.h>
#include <stdlib.h>
typedef struct Node {
    int data;
    struct Node* next;
}node;
node* create()
{
    node* head = (node*)malloc(sizeof(node));
    head->next = NULL;
    int val;
    node*cur = head;
    while(1)
    {
        node *newnode = (node*)malloc(sizeof(node));
        newnode->next = NULL;
        scanf("%d",&val);
        if(val == -1)
        {
             break;
        }
        newnode->data = val;
        cur->next = newnode;
        cur = newnode;
    }
    return head;
}
void insert(node *head, int k)
{
    if(head == NULL)
    {
        return;
    }

    node*cur = head->next;
    node *prev = head;
    while( cur!=NULL)
    {
        if( cur->data > k )
        {
            break;
        }
        prev = cur;
        cur = cur->next;
    }
    node* newnode = (node*)malloc(sizeof(node));
    newnode->data = k;
    newnode->next = cur;
    prev->next = newnode;
}
/*
void dele(node*head,int k )
{
   if(head == NULL)
   {
       return;
   }
   node*prev = head;
   node*cur = head->next;
   node*temp;
   while(cur!=NULL)
   {
       if(cur->data == k)
       {
           temp = cur->next;
           prev->next = cur->next;
           free(cur);
           cur = temp;
           continue;
       }
       prev = cur;
       cur = cur->next;
   }
}*/
void print(node*head)
{
    if(head == NULL)
    {
        return;
    }
    node* cur = head->next;
    while(cur)
    {
        printf("%d",cur->data);
        cur = cur->next;
        if(cur!=NULL)
        {
            printf("->");
        }
    }
    printf("\n");

}
int main()
{
    node* link = create();
    print(link);
    int k;
    scanf("%d",&k);
    insert(link, k);
   //dele(link,k);
    print(link);
    return 0;
}
